$(function(){
        var pagetotal
        $.ajaxSettings.async = false;       //获取数据条数
        $.get("/countDataDictionary",function(data){
            pagetotal=data
        })
        $.ajaxSettings.async = true;
        layui.use('laypage', function(){
            var laypage = layui.laypage;
            //执行一个laypage实例
            laypage.render({
                elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
                ,count: pagetotal //数据总数，从服务端得到
                ,limit: 2
                ,jump: function(obj, data){
                    $.ajaxSettings.async = false;
                    $.get("/findalldataDictionary/"+obj.curr+"/2",function(data){      ////获取数据字典列表信息
                        $("#table01  tr:not(:first)").html("")
                        for(var i=0; i<data.length; i++){
                        $row = $("<tr><td>"+data[i].id+"</td>"+
                                 "<td>"+data[i].dictionaryType+"</td>"+
                                 "<td>"+data[i].descrioptionOfUse+"</td>"+
                                 "<td>"+data[i].code+"</td>"+
                                 "<td>"+data[i].codeValue+"</td>"+
                                 "<td><button type='button' class='layui-btn layui-btn-primary' name='"+data[i].id+"'>"+"修改"+"</a><button type='submit' class='layui-btn layui-btn-primary' name='"+data[i].id+"'>"+"删除"+"</button></td></tr>")
                        $row.appendTo($("#table01"))
                        }
                    })
                    $.ajaxSettings.async = true;
                    $(":button").click(function(){
                        if($(this).attr("type")=="submit"){     //删除字典信息
                            var id = $(this).attr("name")
                            $.ajaxSettings.async = false;
                            $.post("/deleteonedataDictionary/"+id, function(data){
                                if(data==1){
                                    layer.msg("删除成功！！",{time: 500},function(){
                                        window.location.href="dataDictionary.html"
                                    })
                                }else{
                                    layer.msg("删除失败！！")
                                }
                            })
                            $.ajaxSettings.async = true;
                        }
                        else if($(this).attr("type")=="button" && $(this).attr("name")!="xinzeng"&& $(this).attr("id")!="submit01"){         //修改字典信息
                            var id = $(this).attr("name")
                            layui.use('layer', function(){
                                var layer = layui.layer;
                                layer.open({
                                    type: "1",
                                    title: '请输入数据字典信息',
                                    content: $('#form01'),
                                    success: function(index, layero){
                                        $.get("/findbyiddataDictionary/"+id,function(data){
                                            $("#dictionaryType").val(data.dictionaryType)
                                            $("#descrioptionOfUse").val(data.descrioptionOfUse)
                                            $("#code").val(data.code)
                                            $("#codeValue").val(data.codeValue)
                                        })
                                    },
                                    btn: ['确定','取消'],
                                    yes: function(index, layero){
                                       if($("#dictionaryType").val().length==0){
                                            layer.msg("类型不能为空！！",{time:500})
                                       }
                                       else if($("#descrioptionOfUse").val().length==0){
                                            layer.msg("用途描述不能为空！！",{time:500})
                                       }
                                       else if($("#code").val().length==0){
                                            layer.msg("编码不能为空！！",{time:500})
                                       }
                                       else if($("#codeValue").val().length==0){
                                            layer.msg("编码值不能为空！！",{time:500})
                                       }
                                       else{
                                           $.ajaxSettings.async = false;
                                           $.post("/updateonedataDictionary",{id:id, dictionaryType:$("#dictionaryType").val(), descrioptionOfUse:$("#descrioptionOfUse").val(), code:$("#code").val(), codeValue:$("#codeValue").val()},function(data){    //根据id修改字典信息
                                                if(data==1){
                                                     layer.msg("操作成功！！",{time:500},function(){
                                                        layer.close(index)
                                                        window.location.href="dataDictionary.html"
                                                     })
                                                }else{
                                                      layer.msg("操作失败！！",{time:500})
                                                }
                                                })
                                           $.ajaxSettings.async = true;
                                           }
                                    }
                                    ,btn2: function(index, layero){
                                       layer.close(index)

                                      },
                                      end: function(index, layero){
                                        $("#form01").attr("style","display: none")
                                        $("#form01")[0].reset()
                                      }
                                })
                            })
                        }
                        else if($(this).attr("name")=="xinzeng"){       //新增字典信息
                            layui.use('layer', function(){
                                var layer = layui.layer;
                                layer.open({
                                    type: "1",
                                    title: '请输入数据字典信息',
                                    shade: 0.0,
                                    content: $('#form01'),
                                    btn: ['确定','取消'],
                                    yes: function(index, layero){
                                       if($("#dictionaryType").val().length==0){
                                            layer.msg("类型不能为空！！",{time:500})
                                       }
                                       else if($("#descrioptionOfUse").val().length==0){
                                            layer.msg("用途描述不能为空！！",{time:500})
                                       }
                                       else if($("#code").val().length==0){
                                            layer.msg("编码不能为空！！",{time:500})
                                       }
                                       else if($("#codeValue").val().length==0){
                                            layer.msg("编码值不能为空！！",{time:500})
                                       }
                                       else{
                                           $.ajaxSettings.async = false;
                                           $.post("/inertonedataDictionary/",{dictionaryType:$("#dictionaryType").val(), descrioptionOfUse:$("#descrioptionOfUse").val(), code:$("#code").val(), codeValue:$("#codeValue").val()},function(data){
                                                if(data==1){
                                                     layer.msg("操作成功！！",{time:500},function(){
                                                         layer.close(index)
                                                         window.location.href="dataDictionary.html"
                                                     })
                                                }else{
                                                      layer.msg("操作失败！！",{time:500})
                                                }
                                                })
                                           $.ajaxSettings.async = true;
                                           }
                                    }
                                    ,btn2: function(index, layero){
                                       layer.close(index)

                                      },
                                      end: function(index, layero){
                                        $("#form01").attr("style","display: none")
                                        $("#form01")[0].reset()
                                      },
                                      cancel: function(index, layero){
                                            $("#form01")[0].reset()
                                            layer.close(index)
                                      }
                                })
                            })
                        }
                    })
                }
            });
        });
    })